<?php
	class Schools extends CI_Model{

	 	function __construct(){
          	parent::__construct();
      	}


        function get_school_list($limit = 0, $offset = 0, $conditions = array()){
            $where = "status = 1";
            if($conditions){
                if( ($conditions['status'] == 0 || $conditions['status'] == 1 || $conditions['status'] == 2) && $conditions['status'] != 9){
                    $where .= " AND s.status = {$conditions['status']}";
                }
                if(!empty($conditions['school_name'])){
                    $where .= " AND s.school_name LIKE '%{$conditions['school_name']}%'";
                }
                if(!empty($conditions['agent_id'])){
                    $where .= " AND s.agent_id = '{$conditions['agent_id']}'";
                }
            }
            $sql = "SELECT SQL_CALC_FOUND_ROWS id,school_name,school_nick,school_domain,school_logo,school_intro,description,link_tel,link_phone,province_name,city_name,area_name,school_address FROM {$this->db->dbprefix}o2o_school AS s ";
            $sql .= "WHERE $where ORDER BY id DESC ";
            if($limit > 0 || $offset > 0){
               $sql .= "LIMIT $limit, $offset";
            }
            $result = $this->db->query($sql)->result_array();
            if($limit > 0 || $offset > 0){
                $row_num =  $this->db->query('SELECT FOUND_ROWS() as row_num;')->row_array();
                return array("count" => $row_num['row_num'], "list" => $result);
            }else{
                return $result;
            }
        }
	}